package jp.tkym.labs.store.sql;

import jp.tkym.labs.store.ormap.OrMapObject;

class SqlStatementGenerator{
	private SqlGeneratorHelper helper = new SqlGeneratorHelper();
	
	String drop(OrMapObject target){
		return "drop table if exists " + target.getObjectName();
	}
	
	String create(OrMapObject target){
		
		String ret = 
			"create table " +
			target.getObjectName() +
			" (" +
			helper.createCreateColumns(target) +
			")";
		return ret;
	}
	
	String get(OrMapObject target){
		String ret = 
			"select " +
			helper.generateAllColumns(target) +
			" from " +
			target.getObjectName() +
			" where " +
			helper.createWhereByPrimaryKey(target);
		return ret;
	}
	
	String delete(OrMapObject target){
		String ret = 
			"delete from " +  
			target.getObjectName() +  
			" where " + 
			helper.createWhereByPrimaryKey(target);
		return ret;
	}
	
	String update(OrMapObject target){
		String ret = 
			"update " +
			target.getObjectName() + 
			" set " + 
			helper.createUpdateSet(target) +
			" where " + 
			helper.createWhereByPrimaryKey(target);
		return ret;
	}
	
	String insert(OrMapObject table){
		String ret = 
			"insert into " + 
			table.getObjectName() +
			" (" +
			helper.generateAllColumns(table) +
			")" +
			" values (" + 
			helper.createInsertValues(table) +
			")";
		return ret;
	}
	
	String entity(OrMapObject object, String laterSql){
		String ret = 
			"select " +
			helper.generateAllColumns(object) +
			" from " + 
			object.getObjectName();
		if(laterSql != null && laterSql != "") ret += laterSql;		
		return ret;
	}
	
	String key(OrMapObject object, String laterSql){
		String ret = 
			"select " +
			helper.generateKeyColumns(object) +
			" from " + 
			object.getObjectName();
		if(laterSql != null && laterSql != "") ret += laterSql;		
		return ret;
	}
}